#ifndef _SOCKET_H_
#define _SOCKET_H_

#include <sys/types.h>
#include <sys/socket.h>

#include <netinet/in.h>

class SocketException {
	int code;

	public:

	SocketException();
	operator char*();
};

class Socket {
	int fd;

	/* Ha, a bit weird. Suggestions? */
	Socket(void* dummy, int _fd): fd(_fd) {}

	/* No lights, no music, no copies */
	Socket(const Socket&);
	Socket& operator=(Socket&);

	public:

	Socket(int domain = PF_INET, int type = SOCK_STREAM, int protocol = 0);
	virtual ~Socket();

	int Handle() const { return fd; }

	void ReuseAddr(bool);
	void Blocking(bool);

	void Bind(unsigned short port, unsigned long addr = INADDR_ANY);

	void Listen(int backlog = 5);
	Socket* Accept();

	void Connect(const char* addr, unsigned short port);

	ssize_t Receive(void* buf, size_t nbytes);
	ssize_t Send(const void* buf, size_t nbytes);
};

#endif
